package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.idempotent.Idempotent;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.VerificationService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc 预安置管理 - 服刑人员核查
 * @author hak
 * @date 2020年2月10日
 */
@RestController
public class VerificationController {

    @Resource
    private VerificationService verificationService;
    @Resource
    private UserFacade userFacade;

    /**
     * 预安置管理 - 预安置人员核查 - 列表
     * @param pageIndex 起始页 默认:0
     * @param pageSize 止页数 默认:50
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @param state 0:信息未录入完整 1:待核查 2:核查中 3:核查成功人员 4:核查失败人员 5:待办工作 6:已办工作
     * @param nameKey 姓名
     * @param sexKey 性别 1-男 2-女 0-未知的性别 9-未说明的性别
     * @param inputSource 录入来源 01:司法所补录的解矫人员,05:司法所补录的监狱人员,3.看守所录入的服刑人员,4:接口进入的看守所人员,5:监狱录入的服刑人员,6:接口进入的监狱服刑人员,7:社矫录入的服刑人员,8:接口进入的社矫人员,9:监狱通过excel导入,10:社矫通过excel导入,11:看守所通过excel导入,30:湖南看守所个性化对接
     * @param hjKey 户籍类型 01:户籍完整人员、02:查不清户籍人员
     * @param hcType 核查成功类别 1:一次核查成功、2:二次核查成功、3:三次核查成功、4:查不清户籍核查成功
     * @return String
     */
    @RequestMapping("/azbj/verification/info/list")
    public String getVerificationList(Integer pageIndex,Integer pageSize,
                                      @RequestParam(required = false, defaultValue = "-1") String sortField,
                                      @RequestParam(required = false, defaultValue = "-1") String sortOrder,
                                      @RequestParam(required = false, defaultValue = "-1") String state,
                                      @RequestParam(required = false, defaultValue = "-1") String nameKey,
                                      @RequestParam(required = false, defaultValue = "-1") String sexKey,
                                      @RequestParam(required = false, defaultValue = "-1") String inputSource,
                                      @RequestParam(required = false, defaultValue = "-1") String hjKey,
                                      @RequestParam(required = false, defaultValue = "-1") String hcType) {
        UserDTO authentication = userFacade.getAuthentication();
        return verificationService.getVerificationList(pageIndex,pageSize,
                sortField,
                sortOrder,
                authentication.getDepartid(),
                authentication.getLevel(),
                state,
                sexKey,
                nameKey,
                hjKey,
                inputSource,
                authentication.getAccount(),
                hcType);
    }

    /**
     * 修改核查状态
     * @param request request
     * @param prinum prinum
     * @param state 0:未发起核查 1:核查中
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "更新核查状态")
    @Idempotent(paramPos = {1,2,3})
    @PostMapping("/azbj/verification/hcstate")
    public Result updateHcState(HttpServletRequest request,
                                @RequestParam String prinum,
                                @RequestParam String state,
                                @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO authentication = userFacade.getAuthentication();
        return verificationService.updateHcState(prinum,state,data, authentication);
    }

    /**
     * 批量修改核查状态
     * @param request request
     * @param prinums prinums
     * @param state state
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "批量更新核查状态")
    @PostMapping("/azbj/verification/plhcstate")
    public Result updateHcStatePl(HttpServletRequest request,
                                  @RequestParam String prinums,
                                  @RequestParam String state,
                                  @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO authentication = userFacade.getAuthentication();
        return verificationService.updateHcStatePl(prinums,state,data,authentication);
    }

    /**
     * 预安置管理 - 预安置人员发起核查 - 核查失败 - 再次发起核查
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "再次发起核查")
    @Idempotent()
    @PostMapping("/azbj/verification/agreestate")
    public Result updateAgreeState(@RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO authentication = userFacade.getAuthentication();
        return verificationService.updateAgreeState(data,authentication);
    }

    /**
     * 转入原侦查机关
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "转入原侦查机关")
    @Idempotent(paramPos = 1)
    @PostMapping("/azbj/verification-zryzcjg")
    public Result saveZryzcjg(HttpServletRequest request,String data) {
        UserDTO authentication = userFacade.getAuthentication();
        return verificationService.saveZryzcjg(data,authentication);
    }

    /**
     * 手机号码、固定电话、单位信息获取办理人员的用户信息
     * @return Map
     */
    @GetMapping("/azbj/user/findUserMess")
    public Map<String,Object> findUserMess() {
        UserDTO userDTO = userFacade.getAuthentication();
        String username = userDTO.getUsername();
        String phone = userDTO.getPhone();
        String telphone = userDTO.getTelphone();
        Map<String,Object> userMess = new HashMap<>(16);
        //设置日期格式
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // new Date()为获取当前系统时间
        String nowTime = df.format(new Date());
        userMess.put("username",username);
        userMess.put("phone",phone);
        userMess.put("nowTime",nowTime);
        userMess.put("telphone",telphone);
        return userMess;
    }

    /**
     * 预安置管理 - 预安置人员核查 - 待办工作 - 办理
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "更新", value = "司法厅,地市司法局,区县司法局办理")
    @Idempotent(paramPos = 1)
    @PostMapping("/azbj/verification-tuisong/savePrisonerTs")
    public Result savePrisonerMainAndHcVo(HttpServletRequest request,@RequestParam("data") String data) {
        UserDTO user = userFacade.getAuthentication();
        return verificationService.savePrisonerMainAndHcVo(data,user);
    }

    /**
     * 预安置管理 - 预安置人员核查 - 核查中 - 签收
     * @param priNum 服刑人员编号
     * @return Result
     */
    @Log(type = "更新", value = "司法所签收")
    @Idempotent(paramPos = {0,1})
    @PostMapping("/azbj/verification/signFor")
    public Result signFor(@RequestParam String priNum, @RequestParam String type) {
        UserDTO user = userFacade.getAuthentication();
        return verificationService.signFor(priNum,type,user);
    }

    /**
     * sfbadmin--系统管理--死数据列表
     * @param pageIndex 页码起始位置
     * @param pageSize 每页数量
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @param nameKey 姓名
     * @param sexKey 性别
     * @param inputSource 数据来源 01:司法所补录的解矫人员,05:司法所补录的监狱人员,3.看守所录入的服刑人员,4:接口进入的看守所人员,5:监狱录入的服刑人员,6:接口进入的监狱服刑人员,7:社矫录入的服刑人员,8:接口进入的社矫人员,9:监狱通过excel导入,10:社矫通过excel导入,11:看守所通过excel导入,30:湖南看守所个性化对接
     * @param zdbjKey 重点帮教对象 1:是、2:否
     * @param shenKey 身份证
     * @param zmKey 罪名
     * @param fxKey 服刑单位
     * @param nativepro 省
     * @param nativecity 市
     * @param nativecou 区县
     * @param nativevill 街道/乡镇
     * @param rjStartDate 原判刑期起日
     * @param rjEndDate 释放日期
     * @return String
     */
    @RequestMapping("/azbj/xtgl/ssjList")
    public String getSsjList(Integer pageIndex,Integer pageSize,
                             @RequestParam(required = false, defaultValue = "-1") String sortField,
                             @RequestParam(required = false, defaultValue = "-1") String sortOrder,
                             @RequestParam(required = false, defaultValue = "-1") String nameKey,
                             @RequestParam(required = false, defaultValue = "-1") String sexKey,
                             @RequestParam(required = false, defaultValue = "-1") String inputSource,
                             @RequestParam(required = false, defaultValue = "-1") String zdbjKey,
                             @RequestParam(required = false, defaultValue = "-1") String shenKey,
                             @RequestParam(required = false, defaultValue = "-1") String zmKey,
                             @RequestParam(required = false, defaultValue = "-1") String fxKey,
                             @RequestParam(required = false, defaultValue = "-1") String nativepro,
                             @RequestParam(required = false, defaultValue = "-1") String nativecity,
                             @RequestParam(required = false, defaultValue = "-1") String nativecou,
                             @RequestParam(required = false, defaultValue = "-1") String nativevill,
                             @RequestParam(required = false, defaultValue = "-1") String rjStartDate,
                             @RequestParam(required = false, defaultValue = "-1") String rjEndDate) {
        return verificationService.getSsjList(pageIndex,pageSize,sortField,sortOrder,sexKey,nameKey,inputSource,zdbjKey,shenKey,zmKey,fxKey,nativepro,nativecity,nativecou,nativevill,rjStartDate,rjEndDate);
    }
}